package com.pethospital.controller;

import com.pethospital.common.Result;
import com.pethospital.util.FileUploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileUploadUtil fileUploadUtil;

    /**
     * 通用文件上传接口
     */
    @PostMapping("/upload")
    public Result<String> upload(
            @RequestParam("file") MultipartFile file,
            @RequestParam(value = "type", defaultValue = "other") String type) {
        String fileUrl = fileUploadUtil.uploadFile(file, type);
        return Result.success(fileUrl);
    }
} 